package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.AssetOutStorageDetailQueryDto;
import com.group.eams.pojo.dto.AssetOutStorageQueryDto;
import com.group.eams.pojo.entity.AssetOutStorage;
import com.group.eams.pojo.vo.AssetOutStorageDetailListVo;
import com.group.eams.pojo.vo.AssetOutStorageListVo;
import com.group.eams.service.AssetOutStorageService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资产出库表(AssetOutStorage)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@Controller
@RequestMapping("/assetOutStorage")
@ResponseBody
public class AssetOutStorageController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetOutStorageService assetOutStorageService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "资产出库列表")
    public Result List(AssetOutStorageQueryDto assetOutStorageQueryDto){
        Page<AssetOutStorage> page = new Page<>(assetOutStorageQueryDto.getPage(), assetOutStorageQueryDto.getLimit());

        Page<AssetOutStorageListVo> listVoPage = assetOutStorageService.findAssetOutStorageList(page, assetOutStorageQueryDto);

        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询资产出库信息")
    public Result find(@RequestParam Long id){
        AssetOutStorage assetOutStorage = assetOutStorageService.getById(id);
        return Result.buildSuccess(assetOutStorage);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加资产出库信息")
    public Result add(@RequestBody AssetOutStorage assetOutStorage){
        boolean result = assetOutStorageService.save(assetOutStorage);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改资产出库信息")
    public Result update(@RequestBody AssetOutStorage assetOutStorage){
        boolean result = assetOutStorageService.updateById(assetOutStorage);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ApiOperation(value = "删除资产出库信息")
    public Result add(@RequestParam Long id){
        boolean result = assetOutStorageService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有资产出库信息")
    public Result findAll(){
        List<AssetOutStorage> assetOutStorageList = assetOutStorageService.list();
        return Result.buildSuccess(assetOutStorageList);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    @ApiOperation(value = "批量删除资产出库信息")
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = assetOutStorageService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量添加资产出库信息")
    public Result addBatch(@RequestBody List<AssetOutStorage> assetOutStorageList){
        boolean result = assetOutStorageService.saveBatch(assetOutStorageList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量修改资产出库信息")
    public Result updateBatch(@RequestBody List<AssetOutStorage> assetOutStorageList){
        boolean result = assetOutStorageService.updateBatchById(assetOutStorageList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/assetDetail",method = RequestMethod.GET)
    @ApiOperation(value = "资产出库明细")
    public Result assetList(AssetOutStorageDetailQueryDto assetOutStorageDetailQueryDto){
        Page<AssetOutStorage> page = new Page<>(assetOutStorageDetailQueryDto.getPage(), assetOutStorageDetailQueryDto.getLimit());
        Page<AssetOutStorageDetailListVo> listVoPage = assetOutStorageService.findAssetOutStorageDetailList(page, assetOutStorageDetailQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/findByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号查询资产出库信息")
    public Result findByApplicationNum(@RequestParam String applicationNum){
        AssetOutStorage assetOutStorage = assetOutStorageService.findByApplicationNum(applicationNum);
        return Result.buildSuccess(assetOutStorage);
    }

    //根据单号进行删除
    @RequestMapping(value = "/deleteByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号删除资产出库信息")
    public Result deleteByApplicationNum(@RequestParam String applicationNum){
        int i = assetOutStorageService.deleteByApplicationNum(applicationNum);
        Result<Object> objectResult = i > 0 ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
        return objectResult;
        
    }
    
}

